//
//  WelcomeViewController.swift
//  新浪微博
//
//  Created by 李赛 on 15/5/14.
//  Copyright (c) 2015年 李赛. All rights reserved.
//

import UIKit
import SDWebImage

class WelcomeViewController: UIViewController {

    
    @IBOutlet weak var avatar_icon: UIImageView!
    @IBOutlet weak var bottomConstraint: NSLayoutConstraint!

    @IBOutlet weak var welcomeLabel: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // 判断是否存在用户账户信息
        if let urlString = sharedUserAccount?.avatar_large{
            avatar_icon.sd_setImageWithURL(NSURL(string: urlString))
        }
    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        // 将图片切成圆的
        avatar_icon.layer.cornerRadius = avatar_icon.bounds.size.width * 0.5
        avatar_icon.layer.masksToBounds = true
        
        self.bottomConstraint.constant = view.bounds.size.height - self.bottomConstraint.constant
        
        // 执行动画 
        UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 5, options: nil, animations: { () -> Void in
            self.view.layoutIfNeeded()
            
        }) { (_) -> Void in
            // 显示欢迎文字
            UIView.animateWithDuration(1, animations: { () -> Void in
                    self.welcomeLabel.alpha = 1
                }, completion: { (_) -> Void in
                    NSNotificationCenter.defaultCenter().postNotificationName(SwitchRootViewControllerNotification, object: "Main")
            })
        }
        
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
}
